package su.jet.irc.client.domain;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;

import su.jet.common.irc.protocol.Session;

//[ek] TODO rename by responsibility - ReaderConsole/ReaderApp and WriterApp/WriterConsole
public class ReaderConsole {

	public static final String IP_ADDRESS = "localhost";
	public static final int PORT_NUM = 50001;
	
	public static void main(String[] args) {
		
		try {
			ServerSocket localSocket = new ServerSocket(PORT_NUM);
			Socket connection = localSocket.accept();
			System.out.println("Connected!!!");
			
			Session session = new Session(connection);
			while (true) {
				Object receiveObject = session.recieveObject();
				String inputString = (String)receiveObject;
				System.out.println(inputString);
			}
		} catch (UnknownHostException e) {
			System.out.println("!!! open port error");
		} catch (IOException e) {
			System.out.println("!!! connection error");
		} catch (ClassNotFoundException e) {
			System.out.println("!!! data processing error");
		}
		
	}
}
